define(function() {
	return function($compile, $scope) {
		require([ "PDUtilDir/util", "AppPathDir/group/groupInfos/support",
				"AppPathDir/group/groupInfos/detail", "AppPathDir/group/groupInfos/assign", "AppPathDir/group/groupInfos/leader", "PDUtilDir/inputSelect",
				"Date", "DateCN", "css!DateCss" ], function(Util, Support,
				DetailSupport, AssignSupport, LeaderSupport, inputSelect) {
			/* 查询 start */
			$scope.search = {};
			$scope.cache = {
				status: new Array(),
				statusMap: new Map(),
				oper_data : [ {
					dictName : "小于",
					dictCode : "<"
				}, {
					dictName : "大于",
					dictCode : ">"
				}, {
					dictName : "等于",
					dictCode : "=="
				} ]
			};
			$scope.searchSupport = {
				run : function() {
					$scope.grid.reload({
						queryParam :  {
							model: JSON.stringify($scope.search)
						}
					})
				}
			};
			//封团
			$scope.downSupport = {
				run : function(id) {
					Util.confirm("确认封团？", function() {
						$.ajax({
							url : getServer() + "/flea/hclv/htravelGroup/setGroupOk.htmls",
							data : {
								model: id
							},
							success : function(data) {
								if(data.status != 200){
									return
								}
                                Util.alert(data.message);
								$scope.grid.refresh();
							}
						});
					});
				}
			};
            //解封
            $scope.openSupport = {
                run : function(id) {
                    Util.confirm("确认解封？", function() {
                        $.ajax({
                            url : getServer() + "/flea/hclv/htravelGroup/setGroupUnOk.htmls",
                            data : {
                                model: id
                            },
                            success : function(data) {
                                if(data.status != 200){
                                    return
                                }
                                Util.alert(data.message);
                                $scope.grid.refresh();
                            }
                        });
                    });
                }
            };
			//下单
			$scope.orderSupport = {
				run : function(id) {
					Util.confirm("确认下单？", function() {
						$.ajax({
							url : getServer() + "/flea/hclv/serviceOrder/addServiceOrder.htmls",
							data : {
								model : id
							},
							success : function(data) {
                                if(data.status != 200){
                                    return
                                }
                                Util.alert(data.message);
                                $scope.grid.refresh();
							}
						});
					})
				}
			};
			//回团
			$scope.backSupport = {
				run : function(id) {
					Util.confirm("确认回团？", function() {
						$.ajax({
							url : getServer() + "/flea/hclv/htravelGroup/setGroupIsBack.htmls",
							data : {
								model: id
							},
							success : function(data) {
                                if(data.status != 200){
                                    return
                                }
                                Util.alert(data.message);
                                $scope.grid.refresh();
							}
						});
					});
				}
			};
			//关闭
			$scope.closeSupport = {
				run : function(id) {
					Util.confirm("确认关闭团？", function() {
						$.ajax({
							url : getServer() + "/flea/hclv/htravelGroup/setGroupIsClose.htmls",
							data : {
								model: id
							},
							success : function(data) {
                                if(data.status != 200){
                                    return
                                }
                                Util.alert(data.message);
                                $scope.grid.refresh();
							}
						});
					});
				}
			};
			$scope.detailSupport = DetailSupport($scope, $compile);
			$scope.assignSupport = AssignSupport($scope, $compile);
			$scope.leaderSupport = LeaderSupport($scope, $compile);
			
			//获取团状态
			$.ajax({
				url : getServer() + "/flea/hclv/getTravelGroupStatus.htmls",
				success : function(data) {
					$scope.cache.status = data.data;
					
					$.each(data.data, function(index, row) {
						$scope.cache.statusMap.set(row.dictCode, row.dictName);
					});
					
					// 初始化状态下拉框
					inputSelect.dropCache();
					inputSelect({
						id : "groupStatus",
						key : {
							id : "dictCode",
							name : "dictName",
							data : "data",
						},
						data : $scope.cache.status,
						simpleData : true,
						searchAble : false,
						callback : function(id) {
							$scope.search.groupStatus = id[0];
						}
					});
					$scope.grid = Support.init($scope.cache, $scope.searchSupport,
							$scope.detailSupport, $scope.closeSupport, $scope.orderSupport);
				}
			});
			// 初始化班期
			$("#time_table").datetimepicker({
				// 设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
				language : "cn",
				// 输出格式化
				format : 'yyyy-mm-dd',
				// 直接选择‘今天’
				todayBtn : true,
				// 设置最精确的时间选择视图
				minView : 'month',
				// 高亮当天日期
				todayHighlight : true,
				// 选择完毕后自动关闭
				autoclose : true
			});

			inputSelect.dropCache();
			inputSelect({
				id : "oper1",
				key : {
					id : "dictCode",
					name : "dictName",
					data : "data"
				},
				data : $scope.cache.oper_data,
				simpleData : true,
				searchAble : false,
				callback : function(id) {
					$scope.search.oper1 = id[0];
				}
			});

			inputSelect.dropCache();
			inputSelect({
				id : "oper2",
				key : {
					id : "dictCode",
					name : "dictName",
					data : "data"
				},
				data : $scope.cache.oper_data,
				simpleData : true,
				searchAble : false,
				callback : function(id) {
					$scope.search.oper2 = id[0];
				}
			});
		})
	}
});